package com.maimang.platform.dsp.controller;

import com.maimang.platform.annotation.Log;
import com.maimang.platform.enums.BusinessType;
import com.maimang.platform.dsp.entity.Qualification;
import com.maimang.platform.dsp.service.QualificationService;
import com.maimang.platform.base.BaseController;
import com.maimang.platform.base.Result;
import com.maimang.platform.page.TableDataInfo;
import com.maimang.platform.common.utils.ExcelUtil;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @classname QualificationController
 * @description <br>广告主资质主信息操作处理</br>
 * @author  Rocky
 * @date    2019-12-17 10:11:36
 * @email   jintaozhao@qq.com
 * @version 1.0.0
 */
@Controller
@RequestMapping("/dsp/qualification")
@Api(value = "广告主资质主", description = "广告主资质主 信息操作处理接口")
public class QualificationController extends BaseController {
    private String prefix = "qualification/dsp/qualification";

	@Autowired
	private QualificationService qualificationService;

	@RequiresPermissions("dsp:qualification:view")
	@GetMapping()
	public String qualification() {
	    return prefix + "/qualification";
	}

	/**
	 * 查询广告主资质主列表
	 */
	@ApiOperation(value = "查询列表", notes = "查询广告主资质主列表信息")
	@RequiresPermissions("dsp:qualification:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Qualification qualification) {
		startPage();
        List<Qualification> list = qualificationService.selectQualificationList(qualification);
		return getDataTable(list);
	}


	/**
	 * 导出广告主资质主列表
	 */
	@ApiOperation(value = "导出列表", notes = "导出广告主资质主列表信息到Excel文件")
	@RequiresPermissions("dsp:qualification:export")
    @PostMapping("/export")
    @ResponseBody
    public Result export(Qualification qualification) {
    	List<Qualification> list = qualificationService.selectQualificationList(qualification);
        ExcelUtil<Qualification> util = new ExcelUtil<Qualification>(Qualification.class);
        return util.exportExcel(list, "qualification");
    }

	/**
	 * 新增广告主资质主
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 新增保存广告主资质主
	 */
	@ApiOperation(value = "新增保存", notes = "参数：Qualification")
	@RequiresPermissions("dsp:qualification:add")
	@Log(title = "广告主资质主", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public Result addSave(Qualification qualification) {
		return toResult(qualificationService.insertQualification(qualification));
	}

	/**
	 * 修改广告主资质主
	 */
	@GetMapping("/edit/{advertiserId}")
	public String edit(@PathVariable("advertiserId") Long advertiserId, ModelMap modelMap) {
		Qualification qualification = qualificationService.selectQualificationById(advertiserId);
		modelMap.put("qualification", qualification);
	    return prefix + "/edit";
	}

	/**
	 * 修改保存广告主资质主
	 */
	@ApiOperation(value = "修改保存", notes = "参数：Qualification")
	@RequiresPermissions("dsp:qualification:edit")
	@Log(title = "广告主资质主", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public Result editSave(Qualification qualification) {
		return toResult(qualificationService.updateQualification(qualification));
	}

	/**
	 * 删除广告主资质主
	 */
	@ApiOperation(value = "删除对象", notes = "参数：ids，示例： id1,id2,id3，接口会转转为String[]类型")
	@RequiresPermissions("dsp:qualification:remove")
	@Log(title = "广告主资质主", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public Result remove(String ids) {
		return toResult(qualificationService.deleteQualificationByIds(ids));
	}

}